package utils

import (
	"encoding/json"
	"fmt"
	"gitee.com/layheart/gameServer/api"
	"net"
)

// GetResponse 获取响应参数
func GetResponse(responseStr string) (*api.ResponseData, error) {
	var responseData api.ResponseData
	err := json.Unmarshal([]byte(responseStr), &responseData)
	if err != nil {
		fmt.Println("响应参数转换错误-err:", err)
		return &responseData, err
	}
	return &responseData, err
}

// FailResponse 失败返回数据
func FailResponse(conn net.Conn, errMsg string) {
	// 失败返回数据
	_, err := conn.Write([]byte(errMsg))
	if err != nil {
		fmt.Println("回写失败响应数据失败，err:", err)
		return
	}
}
